//
//  HelpViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/29.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class HelpViewController: KMViewController {
    
    fileprivate let cellID = "helpCell"
    fileprivate let dataArray = [commonProblem,commentsAndFeedback,contactUs]

    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = helpAndFeedback
        createTableView()
    }
    
    //MARK: 创建tableView
    fileprivate func createTableView() {
    
        self.view.backgroundColor = UIColor.mineColor()
        
        let tableView = UITableView.init(frame: .zero, style: .plain)
        tableView.backgroundColor = UIColor.clear
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellID)
        tableView.bounces = false
        tableView.tableFooterView = UIView()
        self.view.addSubview(tableView)
        
        tableView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 20))
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension HelpViewController : UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return dataArray.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return RATIO_H(maxNum: 50)
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath)
        cell.textLabel?.text = dataArray[indexPath.row]
        cell.accessoryType = .disclosureIndicator
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        switch indexPath.row {
        case 0:
            break
        case 1:
            self.navigationController?.pushViewController(FeedbackViewController(), animated: true)
        case 2:
            self.navigationController?.pushViewController(ContactViewController(), animated: true)
            break
        default:
            break
        }
    }
    
}
